//
//  ProgramIntroducedListViewController.m
//  RainbowFM
//
//  Created by Kratos on 14/12/9.
//  Copyright (c) 2014年 RB. All rights reserved.
//

#import "ProgramIntroducedListViewController.h"
#import "ProgramIntroducedViewController.h"

#import "ProgramIntroducedListTableViewCell.h"

#import "ProgramModel.h"

@interface ProgramIntroducedListViewController ()
@property (nonatomic , strong) NSMutableArray *programsList;//栏目列表
@end

@implementation ProgramIntroducedListViewController
-(void)awakeFromNib
{
    self.programsList = [NSMutableArray array];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self updateProgramList];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)updateProgramList
{
    typeof(self) self_ = self;
    [[ProgramModel sharedModel] fetchProgramListWithVip:nil currentPage:1 pageSize:200 result:^(NSArray *list, NSString *msg) {
        [self_.programsList removeAllObjects];
        [self_.programsList addObjectsFromArray:list];
        
        [self_.tableView reloadData];
    }];
}

#pragma mark - table datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_programsList count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ProgramIntroducedListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ProgramIntroducedListTableViewCell"];
    
    [cell updateContents:_programsList[indexPath.row]];
    
    return cell;
    
}



#pragma mark - table delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}




#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([sender isKindOfClass:[ProgramIntroducedListTableViewCell class]]) {
        NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
        
        ProgramItem *item = _programsList[indexPath.row];
        
        NSString *title = item.ACTNAME;
        
        ProgramIntroducedViewController *programIntroducedViewController = [segue destinationViewController];
        programIntroducedViewController.item = item;
        [programIntroducedViewController setTitle:title];
    }
    
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}

@end
